<!DOCTYPE html>
<html lang="en">Lab11 JavaScript函数this指向 17
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>特殊场景this绑定实验</title>
</head>
<body>
<button>按钮</button>
<script>
// 将在这⾥插⼊JavaScript代码
setTimeout(function() {
console.log("定时器函数:", this);
}, 1000);
var btnEl = document.querySelector("button");
btnEl.onclick = function() {
console.log("btn的点击（onclick）:", this);
};
btnEl.addEventListener("click", function() {
console.log("btn的点击（addEventListener）:", this);
});
</script>
</body>
</html>